package com.ndp.fb.util;

import java.math.BigInteger;

/**
 * @Author: Evan on 12/23/2015  11:45.
 * Email: evan.wan@ndpmedia.com
 */
public class TenTo36 {

    /**
     * baseString 递归调用
     * @param num 十进制数
     * @param base 要转换成的进制数
     */
    public static String baseString(int num,int base) {
        String str = "", digit = "0123456789abcdefghijklmnopqrstuvwxyz";
        if(num == 0){
            return "";
        }else {
            str = baseString(num / base,base);
            return str + digit.charAt(num % base);
        }
    }

    public static String baseString(BigInteger num,int base) {
        String str = "", digit = "0123456789abcdefghijklmnopqrstuvwxyz";
        if(num.shortValue() == 0){
            return "";
        }else {
            BigInteger valueOf = BigInteger.valueOf(base);
            str = baseString(num.divide(valueOf),base);
            return str + digit.charAt(num.mod(valueOf).shortValue());
        }
    }

    public static String baseString(Long num) {
        BigInteger big = new BigInteger(num.toString());
        return baseString(big, 36);
    }

    public static String baseString(int num) {
        return baseString(num, 36);
    }


    public static void main(String[] args) {
        System.out.println(baseString(1,36));
        BigInteger big=new BigInteger("999999999999");
        System.out.println(baseString(big,36));
    }
}
